package com.cysion.study.ui

import android.os.Bundle
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.study.ktbox.net.ErrorHandler
import com.cysion.study.ktbox.utils.CLog
import com.cysion.study.ktbox.utils.whiteTextTheme
import com.cysion.other.color
import com.cysion.other.startActivity_ex
import com.cysion.targetfun._subscribe
import com.cysion.study.uibox.bar.TopBar
import com.cysion.study.uibox.dialog.Alert
import com.cysion.study.uibox.dialog.AlertSearch
import com.cysion.study.R
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import com.cysion.study.widget.ShowToast
import kotlinx.android.synthetic.main.activity_recruit_detail.*

//职位详情
class RecruitDetailActivity : BaseActivity() {
    override fun getLayoutId(): Int = R.layout.activity_recruit_detail
    private var curPage = 1
    private var type=""////type 1 职位入口进详情 2 我的应聘入口进详情

    override fun initView() {
//        type = intent.getBundleExtra("key").getString("type")
        whiteTextTheme(color(R.color.main_cl))
        topbar.apply {
            setTitle("职位详情")
            setTexts("搜索", TopBar.Pos.RIGHT)
            setOnTopBarClickListener { obj, pos ->
                if (pos == TopBar.Pos.LEFT) {
                    finish()
                }else if (pos == TopBar.Pos.RIGHT) {
                    AlertSearch.search(self,""){ confirm: Int, start: String, end: String ->
                        CLog.i("@@@搜索"+start+end)
                        curPage=1
//                        getDataList(curPage,start,end)
                    }
                }
            }
        }

        tv_submit.setOnClickListener {
            //应聘
            var bundle = Bundle()
            bundle.putString("type","1")//type 1 职位入口进详情 2 我的应聘入口进详情
            startActivity_ex<AcceptRecruitActivity>("key", bundle)//应聘职位
            finish()

        }
    }
    //加载数据
    override fun initData() {
        super.initData()

    }



    private fun getDataList(page: Int) {
        Alert.loading(self)
        ApiClient.api.getTutorOrderList(UserCache.token,"",curPage.toString()).compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()

                    /*if (curPage == 1) {
                        dataList.clear()
                        if (dataList.size == 0) {
                            multiView.showEmpty()
                        }
                    }
                    if (it.size <= 0) {
                        smartLayout.setEnableLoadMore(false)
                    } else {
                        curPage++
                        dataList.addAll(it)
                        dataAdapter.notifyDataSetChanged()
                        multiView.showContent()
                    }*/
                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)

                }
            }

    }

    private fun dowith(orderId: String, type: String, reason: String) {
        Alert.loading(self)
        ApiClient.api.dowith(UserCache.token, orderId, type, reason).compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()
                    ShowToast("操作成功")

                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)
                }
            }

    }


    override fun closeMvp() {
    }

}
